package com.example.hello.authentication;

import com.example.hello.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 *
 * </p>
 *
 * @author 12071
 * @date 2022/7/22 16:32
 */
public class ShiroUtil {

    @Autowired
    private static SessionDAO sessionDAO;

    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }
    public static User getUser() {
        Object object = getSubject().getPrincipal();
        return (User)object;
    }
    public static Integer getUserId() {
        return getUser().getId();
    }
    public static void logout() {
        getSubject().logout();
    }
}
